#!/bin/sh
 

OSNAME=`uname`
HARDWARENAME=`uname -m`
PLAT=$OSNAME.$HARDWARENAME

CURRENT_DIR=`pwd`
OBJECTS_ROOT=`pwd`/build/linux/objs/
DESTDIR_ROOT=`pwd`/build/linux/


echo "PLAT= $PLAT"
echo "OBJECTS_ROOT=$OBJECTS_ROOT"
echo "DESTDIR_ROOT=$DESTDIR_ROOT"

SHOW_HELP=0
if [ "$1" = "-v" ] ; then
   SHOW_HELP=1
fi

if [ "$1" = "-h" ] ; then
   SHOW_HELP=1
fi

if [ "$1" = "?" ] ; then
   SHOW_HELP=1
fi

if [ "$1" = "help" ] ; then
   SHOW_HELP=1
fi

if [ $SHOW_HELP = 1 ] ; then
	exit 0
fi


if [ "$1" = "install" ] ; then
    ./buildtarball $PLATFORM
    exit 0
fi



echo "nebula"
echo "-----------------------"


case $PLAT in

	Linux.i586 | \
	Linux.i686)
        echo "Configuring for the "$OSNAME" "$HARDWARENAME" platform"
		CPLUS=gcc
		CCOMP=gcc
		LINKER='gcc'
		LIBLINKER='ld'
 		MAKE=make
 		
		COMPILER_FLAGS="-D_REENTRANT -D__USE_POSIX -D__linux__=1 -pipe"
        INCLUDE_FLAG="-include"
		
		CORE_LINK_LIBS="-lpthread -ldl -lstdc++ -lm -lcrypt"

		SHARED=-shared
		MODULE_LIBS=
		
		if [ -f /usr/include/socketbits.h ]; then
			NEED_SOCKETBITS=1
			export NEED_SOCKETBITS
		fi
		;;
esac

	

if [ "$*" = "install" ] ; then

        if [ `uname` != "SunOS" ]; then
                USERID=`id -u`
        else
                USERID=`/usr/xpg4/bin/id -u`
        fi

        if [ $USERID != 0 ]; then
                echo "You must be root to perform an \"install\" build"
                exit 1
        fi
fi

echo Building for $PLAT with $CPLUS

	export CPLUS
	export CCOMP
	export LINKER
	export LIBLINKER
	export COMPILER_FLAGS
	export INCLUDE_FLAG
	export CORE_LINK_LIBS
	export SHARED
	export MODULE_LIBS
	export OBJECTS_ROOT
	export DESTDIR_ROOT

	
	echo Building mcp for $PLAT with $CPLUS
	#cd utlis/CommonUtilitiesLib/
	$MAKE -f Makefile.POSIX $*
	#cd $CURRENT_DIR
	


	if [ "$*" = "install" ] ; then
		cd ..
		pwdi
		echo
		./DSS_MakeRoot /
	fi


